﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KCMS.BusinessLogic.Interfaces;
using StructureMap;
using AutoMapper;

namespace KCMS.Controllers
{
    public class ProductCategoryController : Controller
    {

        private IProductCategoryService pService = ObjectFactory.GetInstance<IProductCategoryService>();
        private IBrendService brendService = ObjectFactory.GetInstance<IBrendService>();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Show(String code, String brend=null)
        {
            var category = pService.getByCode(code);
            var model = Mapper.Map<BusinessLogic.Models.ProductCategory, KCMS.Web.Models.ProductCategoryViewModel>(category);
            try
            {
                var brendModel = brendService.getByCode(brend);
                ViewData["BrendId"] = brendModel.Id;
                return View("ShowWithBrend",model);
            }
            catch
            {
                return View(model);
            }
        }
        public ActionResult ShowWithBrend(String code, String brend)
        {
            var category = pService.getByCode(code);
            var model = Mapper.Map<BusinessLogic.Models.ProductCategory, KCMS.Web.Models.ProductCategoryViewModel>(category);
            try
            {
                var brendModel = brendService.getByCode(brend);
                ViewData["BrendId"] = brendModel.Id;
                return View(model);
            }
            catch
            {
                return RedirectToAction("Show", new { code = code });
            }
         }

        public ActionResult ShowPartail(String code)
        {

            var category = pService.getByCode(code);
            var model = Mapper.Map<BusinessLogic.Models.ProductCategory, KCMS.Web.Models.ProductCategoryViewModel>(category);
            return PartialView(model);
        }




    }
}
